package gateway.config.security.login;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 顺序：2
 * 自定义认证管理器
 *
 * @author 米泽鹏
 * @since 2021-07-31 4:47 下午
 */
@Component
public class CustomAuthenticationManager implements AuthenticationManager {

	@Resource
	private CustomAuthenticationProvider customAuthenticationProvider;

	@Override
	public Authentication authenticate(Authentication authentication) throws AuthenticationException {
		Authentication result = customAuthenticationProvider.authenticate(authentication);
		if (result == null) {
			throw new AuthenticationServiceException("认证失败");
		}
		return result;
	}

}
